<template>
  <div v-show="earlyModuleList.length" class="swiperContent" :class="isOpenMenu ? 'swiperContentOpen' : ''">
    <div class="swiper-container" ref="swiperContainer">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <span class="top rank">最顶部</span>
        </div>
        <div class="swiper-slide" v-for="(item, index) in earlyModuleList" :key="index">
          <div class="module" @click.stop="jumpPage(item)">
            <div class="moduleIcon" :class="path == item.router ? 'moduleActive' : ''">
              <svg-icon class="sveIcon" v-if="item.icon" :icon-class="item.icon" />
              <i v-else class="el-icon-folder-add"></i>
            </div>
            <div class="name">{{ item.menuName }}</div>
          </div>
        </div>
        <div class="swiper-slide">
          <span class="bottom rank">最底部</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import Swiper from 'swiper';
import earlyWarningCenter from "@/api/earlyWarningCenter";

export default {
  name: 'VerticalSwiper',
  props: {},
  computed: {
    ...mapGetters([
      'isOpenMenu',
    ])
  },
  watch: {
    $route (v) {
      this.path = v.path;
      console.log(v)
    },
    isOpenMenu (v) {
      console.log(v)
      this.queryByLoginUser();
    }
  },
  data () {
    return {
      path: '',
      earlyModuleList: [],
      openModule: true
    }
  },
  mounted () {
    setTimeout(() => {
      this.queryByLoginUser();
    }, 1000)
  },
  methods: {
    jumpPage (row) {
      this.$router.push({ path: row.router });
    },
    initSwiper () {
      this.path = this.$route.path;
      const swiperContainer = this.$refs.swiperContainer;
      new Swiper(swiperContainer, {
        direction: 'vertical', // 设置垂直方向滑动  
        slidesPerView: 5, // 设置每次只显示一个slide  
        spaceBetween: 10, // 设置slide之间的间距  
        freeMode: true, // 启用自由模式，允许slide自由滑动  
        resistanceRatio: 0, // 设置滑动阻力为0，使滑动更加流畅  
        // 注意：resistanceRatio 实际上在 Swiper 的某些版本中可能不存在或表现不同。  
        // 你可能需要调整其他参数如 freeModeMomentumRatio、freeModeMomentumVelocityRatio 等来达到类似效果。  
        mousewheel: {
          enable: true, // 启用鼠标滚轮控制滑动  
          releaseOnEdges: true, // 当滑动到边缘时释放鼠标滚轮事件，防止继续滚动页面  
          forceToAxis: true, // 强制滚轮事件仅沿一个轴向滚动  
          sensitivity: 2, // 滚轮滚动的灵敏度  
        },
        // 其他可能有助于滑动流畅性的设置  
        // (这些设置取决于你的具体需求和Swiper的版本)  
        momentumRatio: 1, // 动量滑动比率，调整滑动后的惯性滚动效果  
        momentumBounce: true, // 启用动量反弹效果，使滑动更加自然  
        momentumLimitTime: 300, // 动量滑动持续的时间（毫秒）  
        // ...  
      });
    },
    colseModule () {
      this.$store.commit('settings/setMenuFlag')
    },
    queryByLoginUser () {
      earlyWarningCenter.queryByLoginUser({}).then(res => {
        if (res.code == 1)
        {
          this.earlyModuleList = res.data;
          setTimeout(() => {
            this.initSwiper();
          }, 100)
        } else
        {
          this.earlyModuleList = [];
        };
      }).catch(err => {
        console.log(err);
      })
    },
  },
};
</script>

<style lang="scss" scoped>
.swiperContent {
  width: 100px;
  height: calc(100vh - 50px);
  position: fixed;
  z-index: 999;
  bottom: 0;
  right: -120px;
  background: linear-gradient(to right, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.8));
  box-shadow: 0 0px 30px 10px rgba(0, 21, 41, 0.1);
  transition: all 0.3s;
}

.swiperContentOpen {
  right: 0;
}

.swiper-container {
  width: 100px;
  height: 600px;
  /* 根据需要设置容器高度 */
  overflow: hidden;
  /* 隐藏超出容器的内容 */
  position: absolute;
  top: 50%;
  right: 0;
  transform: translateY(-50%);
}

.swiper-slide {
  display: flex;
  align-items: center;
  justify-content: space-around;
  margin: 0 auto;
  text-align: center;
  position: relative;

  .rank {
    line-height: 60px;
    font-size: 12px;
    color: #999999;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
  }

  .top {
    bottom: 0;
  }

  .bottom {
    top: 0;
  }

  .module {
    width: 100%;
    border-radius: 8px;

    .moduleIcon {
      width: 60px;
      height: 60px;
      background: linear-gradient(0deg, #62b6fa, #2184d4);
      border: 1px solid #2184d4;
      border-radius: 10px;
      margin: 0 auto;
      text-align: center;
      line-height: 60px;
      color: #ffffff;
      font-size: 18px;
      margin: 0 auto;
    }


    .moduleActive {
      border-top: 4px solid #03508f;
      border-left: 6px solid #1c374d;
    }

    .name {
      margin-top: 10px;
      color: #333333;
      width: 100px;
      text-align: center;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      -o-text-overflow: ellipsis;
      font-size: 12px;
    }
  }

}
</style>